<!DOCTYPE html>
<html lang=zh>
<head>
    <meta charset="utf-8">
    
    <title>Java命名与注释 | 紫焱</title>
    
    
        <meta name="keywords" content="语法规则" />
    
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="java命名规范1、项目名全部小写2、包名全部小写3、类名首字母大写，若类名由多个单词构成，每个单词首字母大写，称大驼峰命名法1public class HelloWorld()&amp;#123;&amp;#125; 4、变量名、方法名首字母小写，若其由多个单词构成，每个单词首字母大写，即小驼峰命名法12public void sayHello()&amp;#123; &amp;#125;String userName =&amp;q">
<meta name="keywords" content="语法规则">
<meta property="og:type" content="article">
<meta property="og:title" content="Java命名与注释">
<meta property="og:url" content="http://yoursite.com/2018/08/12/Java命名注释/index.html">
<meta property="og:site_name" content="紫焱">
<meta property="og:description" content="java命名规范1、项目名全部小写2、包名全部小写3、类名首字母大写，若类名由多个单词构成，每个单词首字母大写，称大驼峰命名法1public class HelloWorld()&amp;#123;&amp;#125; 4、变量名、方法名首字母小写，若其由多个单词构成，每个单词首字母大写，即小驼峰命名法12public void sayHello()&amp;#123; &amp;#125;String userName =&amp;q">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-09-07T12:10:40.700Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java命名与注释">
<meta name="twitter:description" content="java命名规范1、项目名全部小写2、包名全部小写3、类名首字母大写，若类名由多个单词构成，每个单词首字母大写，称大驼峰命名法1public class HelloWorld()&amp;#123;&amp;#125; 4、变量名、方法名首字母小写，若其由多个单词构成，每个单词首字母大写，即小驼峰命名法12public void sayHello()&amp;#123; &amp;#125;String userName =&amp;q">
    

    
        <link rel="alternate" href="/atom.xml" title="紫焱" type="application/atom+xml" />
    

    
        <link rel="icon" href="/favicon.ico" />
    

    <link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/libs/open-sans/styles.css">
    <link rel="stylesheet" href="/libs/source-code-pro/styles.css">

    <link rel="stylesheet" href="/css/style.css">
    <script src="/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="/libs/jquery/plugins/cookie/1.4.1/jquery.cookie.js"></script>
    
    
        <link rel="stylesheet" href="/libs/lightgallery/css/lightgallery.min.css">
    
    
        <link rel="stylesheet" href="/libs/justified-gallery/justifiedGallery.min.css">
    
    
    
    


    
        <script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    
</head>

<body>
    <div id="container">
        <header id="header">
    <div id="header-main" class="header-inner">
        <div class="outer">
            <a href="/" id="logo">
                <i class="logo"></i>
                <span class="site-title">紫焱</span>
            </a>
            <nav id="main-nav">
                
                    <a class="main-nav-link" href="/">首页</a>
                
                    <a class="main-nav-link" href="/archives">归档</a>
                
                    <a class="main-nav-link" href="/categories">分类</a>
                
                    <a class="main-nav-link" href="/tags">标签</a>
                
                    <a class="main-nav-link" href="/about">关于</a>
                
            </nav>
            
            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="想要查找什么..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div>
        </div>
    </div>
    <div id="main-nav-mobile" class="header-sub header-inner">
        <table class="menu outer">
            <tr>
                
                    <td><a class="main-nav-link" href="/">首页</a></td>
                
                    <td><a class="main-nav-link" href="/archives">归档</a></td>
                
                    <td><a class="main-nav-link" href="/categories">分类</a></td>
                
                    <td><a class="main-nav-link" href="/tags">标签</a></td>
                
                    <td><a class="main-nav-link" href="/about">关于</a></td>
                
                <td>
                    
    <div class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
    </div>

                </td>
            </tr>
        </table>
    </div>
</header>

        <div class="outer">
            
            
                <aside id="sidebar">
   
        
    <div class="widget-wrap" id='categories'>
        <h3 class="widget-title">
            <span>分类</span>
            &nbsp;
            <a id='allExpand' href="#">
                <i class="fa fa-angle-double-down fa-2x"></i>
            </a>
        </h3>
        
        
        
         <ul class="unstyled" id="tree" > 
                    <li class="directory open">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder-open"></i>
                            &nbsp;
                            Java
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory open">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder-open"></i>
                            &nbsp;
                            基础语法
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/2018/08/12/Java安装/">Java环境安装</a></li>  <li class="file"><a href="/2018/08/12/Java数据类型/">Java数据类型</a></li>  <li class="file"><a href="/2018/08/12/Java修饰符/">Java修饰符</a></li>  <li class="file active"><a href="/2018/08/12/Java命名注释/">Java命名与注释</a></li>  <li class="file"><a href="/2018/08/12/Java运算符/">Java运算符</a></li>  <li class="file"><a href="/2018/09/07/Java语句/">Java语句</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            git
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/2018/12/01/git操作命令/">git操作命令</a></li>  </ul> 
                    </li> 
                     <li class="file"><a href="/2018/08/11/index/">index</a></li>  </ul> 
    </div>
    <script>
        $(document).ready(function() {
            var iconFolderOpenClass  = 'fa-folder-open';
            var iconFolderCloseClass = 'fa-folder';
            var iconAllExpandClass = 'fa-angle-double-down';
            var iconAllPackClass = 'fa-angle-double-up';
            // Handle directory-tree expansion:
            // 左键单独展开目录
            $(document).on('click', '#categories a[data-role="directory"]', function (event) {
                event.preventDefault();

                var icon = $(this).children('.fa');
                var expanded = icon.hasClass(iconFolderOpenClass);
                var subtree = $(this).siblings('ul');
                icon.removeClass(iconFolderOpenClass).removeClass(iconFolderCloseClass);
                if (expanded) {
                    if (typeof subtree != 'undefined') {
                        subtree.slideUp({ duration: 100 });
                    }
                    icon.addClass(iconFolderCloseClass);
                } else {
                    if (typeof subtree != 'undefined') {
                        subtree.slideDown({ duration: 100 });
                    }
                    icon.addClass(iconFolderOpenClass);
                }
            });
            // 右键展开下属所有目录
            $('#categories a[data-role="directory"]').bind("contextmenu", function(event){
                event.preventDefault();
                
                var icon = $(this).children('.fa');
                var expanded = icon.hasClass(iconFolderOpenClass);
                var listNode = $(this).siblings('ul');
                var subtrees = $.merge(listNode.find('li ul'), listNode);
                var icons = $.merge(listNode.find('.fa'), icon);
                icons.removeClass(iconFolderOpenClass).removeClass(iconFolderCloseClass);
                if(expanded) {
                    subtrees.slideUp({ duration: 100 });
                    icons.addClass(iconFolderCloseClass);
                } else {
                    subtrees.slideDown({ duration: 100 });
                    icons.addClass(iconFolderOpenClass);
                }
            })
            // 展开关闭所有目录按钮
            $(document).on('click', '#allExpand', function (event) {
                event.preventDefault();
                
                var icon = $(this).children('.fa');
                var expanded = icon.hasClass(iconAllExpandClass);
                icon.removeClass(iconAllExpandClass).removeClass(iconAllPackClass);
                if(expanded) {
                    $('#sidebar .fa.fa-folder').removeClass('fa-folder').addClass('fa-folder-open')
                    $('#categories li ul').slideDown({ duration: 100 });
                    icon.addClass(iconAllPackClass);
                } else {
                    $('#sidebar .fa.fa-folder-open').removeClass('fa-folder-open').addClass('fa-folder')
                    $('#categories li ul').slideUp({ duration: 100 });
                    icon.addClass(iconAllExpandClass);
                }
            });  
        });
    </script>

    
    <div id="toTop" class="fa fa-angle-up"></div>
</aside>
            
            <section id="main"><article id="post-Java命名注释" class="article article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
        
            <header class="article-header">
                
                    <div class="article-meta">
                        
    <div class="article-category">
    	<i class="fa fa-folder"></i>
        <a class="article-category-link" href="/categories/Java/">Java</a><i class="fa fa-angle-right"></i><a class="article-category-link" href="/categories/Java/基础语法/">基础语法</a>
    </div>

                        
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link" href="/tags/语法规则/">语法规则</a>
    </div>

                        
    <div class="article-date">
        <i class="fa fa-calendar"></i>
        <a href="/2018/08/12/Java命名注释/">
            <time datetime="2018-08-12T00:26:19.000Z" itemprop="datePublished">2018-08-12</time>
        </a>
    </div>


                        
                            <i class="fa fa-bar-chart"></i>
                            <span id="busuanzi_container_site_pv"><span id="busuanzi_value_page_pv"></span></span>    
                        
                        
                            <div class="article-meta-button">
                                <a href='https://gitee.com/liuyi6/liuyi6/raw/hexo/source/_posts/Java命名注释.md'> Source </a>
                            </div>
                            <div class="article-meta-button">
                                <a href='https://gitee.com/liuyi6/liuyi6/edit/hexo/source/_posts/Java命名注释.md'> Edit </a>
                            </div>
                            <div class="article-meta-button">
                                <a href='https://gitee.com/liuyi6/liuyi6/commits/hexo/source/_posts/Java命名注释.md'> History </a>
                            </div>
                        
                    </div>
                
                
    
        <h1 class="article-title" itemprop="name">
            Java命名与注释
        </h1>
    

            </header>
        
        
        <div class="article-entry" itemprop="articleBody">
        
        
            
        
        
            <h2 id="java命名规范"><a href="#java命名规范" class="headerlink" title="java命名规范"></a>java命名规范</h2><p>1、项目名全部小写<br>2、包名全部小写<br>3、类名首字母大写，若类名由多个单词构成，每个单词首字母大写，称大驼峰命名法<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">public class HelloWorld()&#123;&#125;</span><br></pre></td></tr></table></figure></p>
<p>4、变量名、方法名首字母小写，若其由多个单词构成，每个单词首字母大写，即小驼峰命名法<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">public void sayHello()&#123; &#125;</span><br><span class="line">String userName =&quot;luis&quot;;</span><br></pre></td></tr></table></figure></p>
<p>5、常量名全部大写<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">public static final String ATHOR=&quot;luis&quot;;</span><br></pre></td></tr></table></figure></p>
<p>6、以上所有命名遵循规则：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">名称只能由数字、字母、下划线、$符组成</span><br><span class="line">不能以数字开头</span><br><span class="line">不能是有Java的关键字和保留字</span><br><span class="line">严禁使用汉字和拼音</span><br></pre></td></tr></table></figure></p>
<h2 id="java注释规范"><a href="#java注释规范" class="headerlink" title="java注释规范"></a>java注释规范</h2><p>注释分为文档注释(/<em>**</em> <em>/ )、行注释(//) 、块注释(/</em> */ )三种。<br>其中文档注释可用来注释类、接口、静态方法、成员方法、静态变量、成员变量、常量<br>块注释可用来注释文件头、算法实现、方法中的复杂代码块、修改记录<br>行注释一般用来注释局部变量</p>
<p>下面将对常用的几种注释进行展示：<br>1、类注释<br>在每个类前面加上类注释，注释内容包括类或接口名，类和接口功能描述，作者，创建日期，所属公司、版本等：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line">* @description：测试类</span><br><span class="line">* @ClassName：HelloWorld.java</span><br><span class="line">* @author luis</span><br><span class="line">* @Date   2018-7-16 18:10:31</span><br><span class="line">* @version 1.00</span><br><span class="line">*/</span><br></pre></td></tr></table></figure></p>
<p>2、属性注释<br>在每个属性前面必须加上属性注释，注释如下:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">/** 字符串信息 */</span><br><span class="line">private String strMsg = null;</span><br></pre></td></tr></table></figure></p>
<p>3、方法注释<br>在每个方法前面必须加上方法注释，注释如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line">* 类方法的详细使用说明</span><br><span class="line">* @param 参数1 参数1的使用说明</span><br><span class="line">* @param 参数2 参数1的使用说明</span><br><span class="line">* @return 返回结果的说明</span><br><span class="line">* @throws 异常类型.错误代码 注明从此类方法中抛出异常的说明</span><br><span class="line">*/</span><br></pre></td></tr></table></figure></p>
<p>4、构造方法注释<br>在每个构造方法前面必须加上注释，注释如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line">* 构造方法的详细使用说明</span><br><span class="line">* @param 参数1 参数1的使用说明</span><br><span class="line">* @throws 异常类型.错误代码 注明从此类方法中抛出异常的说明</span><br><span class="line">*/</span><br></pre></td></tr></table></figure></p>
<p>5、方法内部注释<br>在方法内部使用单行或者多行注释，该注释根据实际情况添加。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//背景颜色</span><br><span class="line">Color bgColor = Color.RED</span><br></pre></td></tr></table></figure></p>
<p>以上为在java开发过程中需遵守的命名规范与注释规范，希望能够对开始java学习的我们有所帮助。</p>

            </div>
        
        <footer class="article-footer">
        </footer>
    </div>
</article>


    
<nav id="article-nav">
    
        <a href="/2018/08/12/Java安装/" id="article-nav-newer" class="article-nav-link-wrap">
            <strong class="article-nav-caption">上一篇</strong>
            <div class="article-nav-title">
                
                    Java环境安装
                
            </div>
        </a>
    
    
        <a href="/2018/08/11/index/" id="article-nav-older" class="article-nav-link-wrap">
            <strong class="article-nav-caption">下一篇</strong>
            <div class="article-nav-title">index</div>
        </a>
    
</nav>





    
    




<!-- baidu url auto push script -->
<script type="text/javascript">
    !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=window.location.href,o=document.referrer;if(!e.test(r)){var n="//api.share.baidu.com/s.gif";o?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var t=new Image;t.src=n}}(window);
</script>     
</section>
        </div>
        <footer id="footer">
    <div class="outer">
        <div id="footer-info" class="inner">
            luis &copy; 2018 
            <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/80x15.png" /></a>
            <br> Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>. Theme - <a href="https://github.com/zthxxx/hexo-theme-Wikitten">wikitten</a>
            
                <br>
                <span id="busuanzi_container_site_pv"><i class="fa fa-eye"></i> <span id="busuanzi_value_site_pv"></span></span>
                &nbsp;|&nbsp;
                <span id="busuanzi_container_site_pv"><i class="fa fa-user"></i> <span id="busuanzi_value_site_uv"></span></span>
            
        </div>
    </div>
</footer>

        

    
        <script src="/libs/lightgallery/js/lightgallery.min.js"></script>
        <script src="/libs/lightgallery/js/lg-thumbnail.min.js"></script>
        <script src="/libs/lightgallery/js/lg-pager.min.js"></script>
        <script src="/libs/lightgallery/js/lg-autoplay.min.js"></script>
        <script src="/libs/lightgallery/js/lg-fullscreen.min.js"></script>
        <script src="/libs/lightgallery/js/lg-zoom.min.js"></script>
        <script src="/libs/lightgallery/js/lg-hash.min.js"></script>
        <script src="/libs/lightgallery/js/lg-share.min.js"></script>
        <script src="/libs/lightgallery/js/lg-video.min.js"></script>
    
    
        <script src="/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>
    
    
        <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true,
            TeX: {
                equationNumbers: {
                  autoNumber: 'AMS'
                }
            }
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<script async src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    



<!-- Custom Scripts -->
<script src="/js/main.js"></script>

    </div>
</body>
</html>